/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scheduler.fixtures;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import se392.ateam2006.meetingmgmt.MeetingMgmtRemote;
import se392.ateam2006.meetingmgmt.meeting.MeetingEntity;
import se392.ateam2006.resourcemgmt.ResourceMgmtRemote;
import se392.ateam2006.resourcemgmt.participant.exclusionset.ExclusionRangeEntity;

/**
 *
 * @author Caroline
 */
public class PreferenceSetForMeeting extends fit.RowFixture {
    
    private MeetingMgmtRemote meetingManage;
    private ResourceMgmtRemote resourceManage;
    private String meetingId;
    
    public PreferenceSetForMeeting(MeetingMgmtRemote meetingManage, ResourceMgmtRemote resourceManage,String meetingId) {
        this.meetingManage = meetingManage;
        this.resourceManage = resourceManage;
        this.meetingId = meetingId;
    }

    @Override
    public Object[] query() throws Exception {
        MeetingEntity meeting = meetingManage.findMeetingById(meetingId);
            if (meeting != null) {
                SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd kk:mm");
                ArrayList exclusionList = new ArrayList();
                Collection<ExclusionRangeEntity> exclusions = resourceManage.getExclusionSetsForMeetingId(meetingId);
                for (ExclusionRangeEntity ex : exclusions) {
                    if (ex.isPreferenceSet()) {
                        exclusionList.add(new ExclusionRangeEntityParticipantShell(
                                ex.getUserEnt().getEmail(),
                                format.format(ex.getStartDate().getTime()),
                                format.format(ex.getEndDate().getTime())));
                    }                    
                }
                return exclusionList.toArray();
            }
            System.err.println("Couldn't find meeting " + meetingId);
            return null;
    }

    @Override
    public Class getTargetClass() {
        return ExclusionRangeEntityParticipantShell.class;
    }   
    

}

